var articleModel = require('../model/articleModel');
var mongoose = require('mongoose');
mongoose.connection.openUri('mongodb://localhost/myBlog');


module.exports = function (app) {


  // app.get('/', function (req, res, next) {
  //   console.log('************************');
  //   console.log(new Date());
  //   next();
  // });


  app.get('/', function (req, res) {

    articleModel.count(function (error, article_count) {
      console.log('count: '+article_count);

      var pass_value = {article_count: article_count};
      res.render('index', pass_value);
    });


    // res.redirect('/login');
  });


  // app.use('/single', require('./single'));
  // app.use('/contact', require('./contact'));
  // app.use('/about', require('./about'));


  app.use('/', require('./login'));
  app.use('/', require('./article'));
  app.use('/add-article', require('./add-article'));



  // 404 page
  app.use(function (req, res) {
    if (!res.headersSent) {
      res.status(404).render('404');
    }
  });
};